<?php

/*
 * Niken Larasati
 * larasati.n@students.amikom.ac.id
 */

class gol_darah extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    function form_gol_darah() {
        $this->template->load('halaman_v', 'admin/gol_darah/tambah_goldarah_v');
    }

    function tambah() {
        if ($this->input->post('tambah') != NULL) {
            $data['idgol_darah'] = $this->input->post('idgol_darah');
            $data['gol_darah'] = $this->input->post('gol_darah');

            $this->load->model('umum_m');
            $this->umum_m->tambah('gol_darah', $data);
            $this->tampil();
        }
    }

    function ubah($id = NULL) {
        if ($id != NULL) {
            $this->load->model('umum_m');
            $data['data_gol_darah'] = $this->umum_m->ambil_data('gol_darah', 'idgol_darah = ' . $id)->row();
            $this->template->load('halaman_v', 'admin/gol_darah/ubah_goldarah_v', $data);
        } else {
            redirect('admin/gol_darah');
        }
    }

    function simpan_ubah() {
        if ($this->input->post() != NULL) {
            $gol_darah['idgol_darah'] = $this->input->post('idgol_darah');
            $gol_darah['gol_darah'] = $this->input->post('gol_darah');

            $this->load->model('umum_m');
            if ($this->umum_m->ubah('gol_darah', $gol_darah, 'idgol_darah', $gol_darah['idgol_darah'])) {
                redirect('admin/gol_darah/tampil');
            }
        }
    }

    function tampil() {
        $this->load->model('gol_darah_m');
        $data['gol_darah'] = $this->gol_darah_m->ambil_data();
        $this->template->load('halaman_v', 'admin/gol_darah/tampil_goldarah_v', $data);
    }
    
    function hapus($id = NULL){
        if($id != NULL){
            $this->load->model('umum_m');
            $status = $this->umum_m->cek_relasi_tabel('penduduk','idgol_darah',$id);
            if ($status == 0){
                $this->umum_m->hapus_data_tabel('gol_darah',  array('idgol_darah'=>$id));
                $this->tampil();
            }
        }        
    }

}

?>